<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="日期" prop="criqi">
        <el-date-picker
          v-model="queryParams.criqi"
          type="date"
          placeholder="选择日期"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          clearable
          @keyup.enter.native="handleQuery"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item label="场站名" prop="changzhanid">
        <el-select filterable clearable v-model="queryParams.changzhanid" placeholder="选择场站名" @change="getBuJian1List">
          <el-option v-for="namelist in changzhannameList"
            :key="namelist.czid"
            :label="namelist.czname"
            :value="namelist.czid"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="部件类型" prop="bujianleixingid">
        <el-select filterable clearable v-model="queryParams.bujianleixingid" placeholder="选择部件类型" @change="getBuJian1List">
          <el-option v-for="leixinglist in bujianleixingList"
            :key="leixinglist.bjlxid"
            :label="leixinglist.bjlxname"
            :value="leixinglist.bjlxid"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="部件" prop="bujianid">
        <el-select filterable clearable v-model="queryParams.bujianid" placeholder="选择部件" >
          <el-option v-for="bujianlist in bujianList"
                     :key="bujianlist.bjid"
                     :label="bujianlist.bjname"
                     :value="bujianlist.bjid"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="部件参数" prop="bujiancanshuid">
        <el-select filterable clearable v-model="queryParams.bujiancanshuid" placeholder="选择部件参数" >
          <el-option v-for="namelist in bujiancanshuList"
                     :key="namelist.bjcsid"
                     :label="namelist.bjcsname"
                     :value="namelist.bjcsid"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ruoyi-yuce:ycdataceshi:export']"
        >导出</el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ycdataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="场站名" align="center" prop="changzhanname" />
      <el-table-column label="部件类型" align="center" prop="bujiantype" />
      <el-table-column label="部件" align="center" prop="bujianname" />
      <el-table-column label="部件参数值" align="center" prop="bujiancanshuid" />
      <el-table-column label="日期" align="center" prop="riqi" width="180" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.riqi, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="部件参数值" align="center" prop="bujiancanshu" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getchangzhanList, getbujianleixingList, getbujianList,getbujian1List,  getbujiancanshuList,listYcdata} from "@/api/ruoyi-yuce/ycdataceshi";

export default {
  name: "Ycdataceshi",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 遥测记录表格数据
      ycdataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        criqi: null,
        changzhanid: null,
        bujianleixingid: 49,
        bujianid: null,
        bujiancanshuid: null,
      },
      changzhannameList:[], //场站名称列表
      bujianleixingList:[], //部件类型列表
      bujianList:[], //部件列表
      bujiancanshuList:[],  //部件参数列表
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    console.log("created执行了")
    this.getChangZhanList()
    this.getBuJianLeiXingList()
    this.getBuJianList()
    this.getBuJianCanShuList()
  },
  methods: {
    /** 查询电度数据记录列表 */
    getList() {
      this.loading = true;
      listYcdata(this.queryParams).then(response => {
        this.ycdataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getChangZhanList() {
      getchangzhanList().then(response=>{
        console.log('response',response)
        this.changzhannameList=response
      })
    },
    getBuJianLeiXingList(){
      getbujianleixingList().then(response=>{
        console.log('response',response)
        this.bujianleixingList=response
      })
    },
    getBuJianList(){
      getbujianList(this.queryParams).then(response=>{
        console.log('response',response)
        this.bujianList=response
      })
    },
    getBuJian1List(){
      getbujian1List(this.queryParams).then(response=>{
        console.log('response',response)
        this.bujianList=response
      })
    },
    getBuJianCanShuList(){
      getbujiancanshuList().then(response=>{
        console.log('response',response)
        this.bujiancanshuList=response
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        changzhanid: null,
        bujianleixingid: null,
        bujianid: null,
        criqi: null,
        bujiancanshuid:null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('ruoyi-yuce/ycdataceshi/export', {
        ...this.queryParams
      }, `ycdata_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
